package com.example.mychess;

import java.awt.*;
import java.io.Serializable;
/**
 * @author [Your Name]
 * @since [Version Number]
 * @version [Current Version Number]
 *
 * @package com.example.mychess
 * @description 此类用于定义一个可序列化的消息对象，该对象包含了一系列属性以支持在线象棋游戏中的通信和交互操作。
 * 消息内容可以是任何类型，通过 {@link #content} 字段存储。
 * 消息发送者、接收者以及与用户相关的信息存储在 {@link User} 对象中，并通过 {@link #user} 字段访问。
 * 使用枚举 {@link Type} 来表示不同的消息类型，涵盖了登录、注册、走棋、吃子等多种游戏操作。
 * 除此之外，还包括了表示棋盘坐标信息的 {@link Point} 类型变量（如：{@link #next} 表示移动目标位置），
 * 以及与具体游戏状态相关的其他字段，如棋子实例 ({@link #first}) 和表格编号 ({@link #table}) 等。
 *
 * @see Serializable
 * @see User
 * @see Chess
 * @see Point
 */
public class Message implements Serializable {
    private Object content;
    private User user;
    private Type type;
    private String from;
    private String frompassword;
    private int table;
    private String to;
    private Chess first;
    private Point next;
    private int[] a;

    /**
     * @return the array of integers stored in this message, which can be used for holding additional data relevant to the message context.
     */
    public int[] getA() {
        return a;
    }

    /**
     * Sets the array of integers that will be associated with this message.
     * This field is intended to carry extra information or parameters needed for specific message types.
     *
     * @param a an array of integers to store as part of the message content
     */
    public void setA(int[] a) {
        this.a = a;
    }

    /**
     * Retrieves the chess piece instance involved in the current action represented by this message.
     * For example, when a move or capture operation occurs, this method returns the chess piece being moved or captured.
     *
     * @return the {@link Chess} object representing the chess piece
     */
    public Chess getFirst() {
        return first;
    }

    /**
     * Assigns the chess piece instance related to the action described in this message.
     * This setter is typically used when constructing messages that involve manipulation of a specific chess piece on the board.
     *
     * @param first the {@link Chess} object to set as the active chess piece for the message
     */
    public void setFirst(Chess first) {
        this.first = first;
    }

    /**
     * Gets the target point on the chessboard where a chess piece should move to or where a certain action takes place.
     *
     * @return the {@link Point} indicating the coordinates on the chessboard
     */
    public Point getNext() {
        return next;
    }

    /**
     * Sets the target point on the chessboard where a chess piece should be moved or where an event is planned.
     * This setter updates the `next` field with a new {@link Point} instance.
     *
     * @param next the new destination {@link Point} on the chessboard
     */
    public void setNext(Point next) {
        this.next = next;
    }

    /**
     * Retrieves the content object encapsulated within this message.
     * The content can be any type and its interpretation depends on the specific message type.
     *
     * @return the generic object representing the content of the message
     */
    public Object getContent() {
        return content;
    }

    /**
     * Sets the content object of this message.
     * The content should be set according to the semantics of the message's {@link Type}.
     *
     * @param content the arbitrary object that forms the core informational payload of the message
     */
    public void setContent(Object content) {
        this.content = content;
    }

    /**
     * Returns the enumerated type of this message, specifying its category or purpose.
     * Examples include login, move, eat (capture), and various other game-related actions.
     *
     * @return the {@link Type} enum value describing the type of the message
     */
    public Type getType() {
        return type;
    }

    /**
     * Assigns the type of this message based on the provided {@link Type} enum value.
     * Setting the type determines how the rest of the message fields should be interpreted.
     *
     * @param type the {@link Type} enum to classify the message
     */
    public void setType(Type type) {
        this.type = type;
    }

    /**
     * Retrieves the username of the user sending this message.
     *
     * @return the String containing the name of the sender
     */
    public String getFrom() {
        return from;
    }

    /**
     * Sets the username of the message sender.
     * This field identifies who initiated the action or communication represented by the message.
     *
     * @param from the String representing the username of the message sender
     */
    public void setFrom(String from) {
        this.from = from;
    }

    /**
     * Gets the username of the recipient targeted by this message.
     *
     * @return the String containing the name of the recipient
     */
    public String getTo() {
        return to;
    }

    /**
     * Sets the username of the recipient for this message.
     * The 'to' field is used when the message is directed at another specific user.
     *
     * @param to the String representing the username of the message recipient
     */
    public void setTo(String to) {
        this.to = to;
    }

    /**
     * Default constructor for the Message class.
     * Initializes an empty Message object with all fields set to their default values (or null).
     */
    public Message() {}

    /**
     * Retrieves the password associated with the user who is sending this message.
     * In a secure system, passwords should not be transmitted in plain text but rather through secure means like encryption or hashing.
     *
     * @return the String containing the password of the sender
     */
    public String getFrompassword() {
        return frompassword;
    }

    /**
     * Sets the password for the user sending this message.
     * It's crucial to handle sensitive information like passwords securely and avoid storing or transmitting them in plaintext.
     *
     * @param frompassword the String representing the password of the sender (ideally hashed or encrypted)
     */
    public void setFrompassword(String frompassword) {
        this.frompassword = frompassword;
    }

    /**
     * Returns the identifier for the table, game session, or room where the action described by this message takes place.
     * This could refer to a specific chess match or a virtual table number within a larger multiplayer environment.
     *
     * @return an integer representing the unique identifier of the table or game session
     */
    public int getTable() {
        return table;
    }

    /**
     * Assigns the identifier for the table, game session, or room relevant to this message.
     * Setting this value helps link the message to a particular context in a multi-table/multi-game environment.
     *
     * @param table an integer that uniquely identifies the table or game session
     */
    public void setTable(int table) {
        this.table = table;
    }

    // 定义消息类型的枚举
    public enum Type {
        LOGIN,
        REG, // 注册
        FORGET, // 忘记密码
        LIST, // 列表相关操作
        JOIN, // 加入游戏或房间
        FIGHT, // 开始对战
        MOVE, // 走棋动作
        EAT, // 吃子动作
        PEACE, // 和棋提议
        DEFEAT, // 认输
        SUCCESS, // 操作成功
        FAILURE, // 操作失败
        UPDATE_SUCCESS, // 更新成功
        LEAVE, // 离开游戏或房间
        A, // 可能是预留字段或者误输入
        ZHUCE, // 注册（同 REG）
        ZHUCE_FAILURE, // 注册失败
        UPDATE_FAILURE // 更新失败
    }

    /**
     * Retrieves the {@link User} object associated with this message.
     * This could be either the sender or a user involved in the action described by the message content.
     *
     * @return the {@link User} instance linked to this message
     */
    public User getUser() {
        return user;
    }

    /**
     * Sets the {@link User} object that is related to this message.
     * This method associates a specific user account with the message, providing context for actions like moves, chat messages, or game invitations.
     *
     * @param user the {@link User} instance to associate with this message
     */
    public void setUser(User user) {
        this.user = user;
    }}
